package view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Color;
import java.awt.Window.Type;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;

import javax.swing.JToolBar;
import javax.swing.JLabel;

import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JList;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;

import model.CustomerHistoryModel.detailsHistory;
import java.awt.event.ActionEvent;

public class CustomerHistoryGui extends AbstractGUI {
	/**
	 * text field for serch
	 */
	private JTextField textField;
	/**
	 * label and write there search
	 */
	
	private JLabel lblSearch = null;
	
	/**
	 * button for search 
	 */
	private JButton btnSearch = null;
	/**
	 * button go to the back screen 
	 */
	private JButton btnBack = null;
		/**
		 * warrning messege for no such a customer
		 */
	private JLabel lblNoSuchA = null;
	/**
	 * Launch the application.
	 */
	/**
	 * this panel is for customer details 
	 */
	private JPanel contentPane2 = null;
	/**
	 * this panel for search
	 */
	private JPanel contentPane1 = null;
	/**
	 * table for details 
	 */
	private JTable table = null;
	

	/**
	 * Create the frame.
	 */
	public CustomerHistoryGui() {
		setForeground(Color.RED);
		setIconImage(Toolkit.getDefaultToolkit().getImage(CustomerHistoryGui.class.getResource("/javax/swing/plaf/metal/icons/Inform.gif")));
		setTitle("Customer History");
		setBackground(Color.GREEN);
		getContentPane().setBackground(Color.PINK);
		getContentPane().setForeground(Color.RED);
		getContentPane().setLayout(null);
		contentPane1 = (JPanel) getContentPane();
		lblSearch = new JLabel("Search a customer:");
		lblSearch.setBounds(10, 106, 124, 25);
		lblSearch.setFont(new Font("Tw Cen MT Condensed Extra Bold", Font.ITALIC, 15));
		getContentPane().add(lblSearch);
		
		textField = new JTextField();
		textField.setBounds(130, 107, 259, 25);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		btnSearch = new JButton("Search");
		btnSearch.setBounds(302, 167, 87, 31);
		getContentPane().add(btnSearch);
		
		btnBack = new JButton("Back");
		btnBack.setBounds(85, 167, 79, 31);
		getContentPane().add(btnBack);
		
		JLabel lblCustomerHistory = new JLabel("Customer History");
		lblCustomerHistory.setBounds(47, 32, 315, 48);
		lblCustomerHistory.setHorizontalAlignment(SwingConstants.CENTER);
		lblCustomerHistory.setFont(new Font("Stencil", Font.ITALIC, 27));
		getContentPane().add(lblCustomerHistory);
		
		lblNoSuchA = new JLabel("no such a customer");
		lblNoSuchA.setBounds(130, 142, 259, 14);
		lblNoSuchA.setVisible(false);
		lblNoSuchA.setForeground(Color.RED);
		getContentPane().add(lblNoSuchA);
		

		

		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 200, 492, 278);
		setVisible(true);
		

	}
	/**
	 * this function init the func for search button
	 * @param listener
	 */
	public void addSearchAL(ActionListener listener)
	{
		btnSearch.addActionListener(listener);
	}
	/**
	 * this function init the func for back button
	 * @param listener
	 */
	public void addBackSalesManGUIhAL(ActionListener listener)
	{
		btnBack.addActionListener(listener);
	}
	/**
	 * clear the text what u write in the text field 
	 */
	public void ClearText()
	{
		textField.setText("");
	}
	
	public String GetTextField()
	{
		return textField.getText();
	}
	
	public void warning_messege()
	{
		lblNoSuchA.setVisible(true);
	}
	
	
	/**
	 * open new panel for details about the customer 
	 * @param s
	 * @param KK
	 */
	public void setnewDetail(String s, Object[][] KK) {
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Object[] ss = new Object[]{"Cmp_id", "Quantity", "date", "comment", "time_call"};
		setBounds(500, 200, 450, 300);
		contentPane2 = new JPanel();
	//	contentPane2.setBorder(new EmptyBorder(5, 5, 5, 5));
	//	setContentPane(contentPane2);
		contentPane2.setLayout(null);
		
		table = new JTable(new DefaultTableModel(KK,ss));
		
		table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		//table.setCellSelectionEnabled(true);
		table.setColumnSelectionAllowed(true);
		table.setVisible(true);
		
		table.setBounds(20, 58, 393, 175);
		contentPane2.add(table);
		
		JLabel lblNewLabel = new JLabel(s);
		lblNewLabel.setBounds(10, 10, 403, 37);
		contentPane2.add(lblNewLabel);
		
		JButton btnNewButton = new JButton("back");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setContentPane(contentPane1);
			}
		});
		btnNewButton.setBounds(350, 0, 89, 23);
		contentPane2.add(btnNewButton);
		
		
		setContentPane(contentPane2);
		setVisible(true);
	}
}
